# coding:utf-8
"""
description:dashboard>side bar页面
"""
from appium.webdriver.common import mobileby

from pages.Dashboard_page import dashboard_page
from common.Gesture_Mainpulation import gesture_mainpulation
from config.GlobalParameter import TEST_Element_YAML
from common.Get_Yaml import get_yaml
import os

testElements = get_yaml(os.path.join(TEST_Element_YAML, "Sidebar.yaml"))


class sidebar_page(dashboard_page):
    by = mobileby.MobileBy()

    HeaderProfilePic_loc = (by.ID, testElements.get_elementInfo(0))  # 点击side bar左上角profile picture，跳转页面
    dashboard_loc = (by.ID, testElements.get_elementInfo(1))  # 点击side bar下的dashboard一行
    devices_loc = (by.ID, testElements.get_elementInfo(2))  # 点击side bar下的devices一行
    scenes_loc = (by.ID, testElements.get_elementInfo(3))  # 点击scene一行
    security_loc = (by.ID, testElements.get_elementInfo(4))  # 点击side bar下的security一行
    homemgmt_loc = (by.ID, testElements.get_elementInfo(5))  # 点击side bar下的Home management一行
    settings_loc = (by.ID, testElements.get_elementInfo(6))  # 点击side bar下的settings一行
    faq_loc = (by.ID, testElements.get_elementInfo(7))  # 点击side bar下的FAQ一行
    DashboardPrivacy_loc = (by.ID, testElements.get_elementInfo(8))  # 点击side bar底部的Privacy Policy一行
    SoftwareLicense_loc = (
        by.ANDROID_UIAUTOMATOR, testElements.get_elementInfo(9))  # 点击side bar底部的Software License & Service Agreement一行
    DashboardNotifs_loc = (by.ID, testElements.get_elementInfo(10))  # 点击side bar页面’Notifications‘，关闭side bar

    def click_btnHeaderProfilePic(self):
        """点击side bar头像"""
        self.find_element(*self.HeaderProfilePic_loc).click()

    def click_dashboardline(self):
        """点击side bar下的dashboard一行"""
        self.find_element(*self.dashboard_loc).click()

    def click_devicesLine(self):
        """点击side bar下的devices一行"""
        self.find_element(*self.devices_loc).click()

    def click_scenesLine(self):
        """点击scene一行"""
        self.find_element(*self.scenes_loc).click()

    def func_clickScene(self):
        """
        从dashboard页面点击
        :return:
        """
        self.click_homeicon()
        self.click_scenesLine()

    def click_securityLine(self):
        """点击side bar下的security一行"""
        self.find_element(*self.security_loc).click()

    def click_homemgmtLine(self):
        """点击side bar下的Home management一行"""
        self.find_element(*self.homemgmt_loc).click()

    def func_clickhomemgmtLine(self):
        """
        从dashboard页面点击
        :return:
        """
        self.click_homeicon()
        self.click_homemgmtLine()

    def click_settings(self):
        """点击side bar下的settings一行"""
        self.find_element(*self.settings_loc).click()

    def click_faqLine(self):
        """点击side bar下的FAQ一行"""
        self.find_element(*self.faq_loc).click()

    def func_faq(self, CheckT):
        """点击side bar下的FAQ一行,跳转页面，断言页标题"""
        self.click_faqLine()
        return super().find_toast(CheckT)

    # 滑动side bar控件，出现底部链接
    swipeDashboard_loc = (by.ID, testElements.get_elementInfo(11))

    def swipe_SideBar(self):
        """滑动side bar控件，出现底部链接"""
        gesture_mainpulation().swipe_up(self.driver, self.find_element(*self.swipeDashboard_loc))

    def click_DashboardPrivacyLine(self):
        """点击side bar底部的Privacy Policy一行"""
        self.find_element(*self.DashboardPrivacy_loc).click()

    def func_Privacy(self, CheckT):
        """点击side bar底部的Privacy Policy一行,跳转页面，断言页标题"""
        self.click_DashboardPrivacyLine()
        return super().find_toast(CheckT)

    def click_SoftwareLicenseLine(self):
        """点击side bar底部的Software License & Service Agreement一行"""
        self.find_element(*self.SoftwareLicense_loc).click()

    def func_SoftwareLicense(self, CheckT):
        """点击side bar底部的Software License & Service Agreement一行,跳转页面，断言页标题"""
        self.swipe_SideBar()
        self.click_SoftwareLicenseLine()
        return super().find_toast(CheckT)

    def click_DashboardNotifs(self):
        """点击side bar页面’Notifications‘，关闭side bar"""
        self.find_element(*self.DashboardNotifs_loc).click()
